﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true"
    CodeBehind="Index.aspx.cs" Inherits="MsgCenter.Web.Pages.Templet.Index" %>
    
<asp:Content ID="Content1" ContentPlaceHolderID="headerContent" runat="server">
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/i18n/grid.locale-cn.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/jquery.jqGrid.min.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/myJqgrid.js") %>"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" runat="server">
    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <table id="grid-table">
                </table>
                <div id="grid-pager">
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        var gridTableID = 'grid-table';
        var gridPagerID = 'grid-pager';
        var ajaxUrl = "../../Handlers/Handler_Templet.ashx";
        function ShowWindow(varTitle, varUrl) {
            var o = {
                title: varTitle,
                href: varUrl
            };
            showColorbox(o);
        }

        function Add() {
            ShowWindow("模板新增", "Option.aspx?type=Add");
        }
        function Delete() {
            var row = $("#" + gridTableID).jqGrid('getGridParam', 'selarrrow');
            if (row.length > 0) {
                var len = row.length;
                var selectUserID = "";
                for (var i = 0; i < len; i++) {
                    var model = $("#" + gridTableID).jqGrid('getRowData', row[i]);
                    if (model.IsAdmin == "是") {
                        $("#" + gridTableID).setSelection(row[i], false);
                    }
                    else {
                        if (selectUserID == "") {
                            selectUserID = model.TempID;
                        }
                        else {
                            selectUserID += "," + model.TempID;
                        }
                    }
                }
                if (selectUserID == "") {
                    showDialogMessage("请先选择数据或不能删除管理员!");
                }
                else {
                    var o = {
                        DeleteData: { method: "Delete", RoleID: selectUserID, random: Math.random() },
                        DeleteURL: ajaxUrl,
                        ReLoad: Reload
                    };
                    showConfirmDialog(o);
                }
            }
            else {
                showDialogMessage("请先选择要删除的数据");
            }
        }

        function Edit() {
            var id = $("#" + gridTableID).getGridParam("selrow");
            if (id) {
                $("#" + gridTableID).resetSelection();
                $("#" + gridTableID).setSelection(id, true);
                var model = $("#" + gridTableID).jqGrid('getRowData', id);
                ShowWindow("模板编辑", "Option.aspx?type=Edit&Guid=" + model.TempID);
            }
            else {
                showDialogMessage("请先选择要修改的数据");
            }
        }

        function Look() {
            var id = $("#" + gridTableID).getGridParam("selrow");
            if (id) {
                var model = $("#" + gridTableID).jqGrid('getRowData', id);
                ShowWindow("模板查看", "Option.aspx?type=Look&Guid=" + model.TempID);
            }
            else {
                showDialogMessage("请先选择要查看的数据");
            }
        }

        jQuery(function ($) {
            var url = ajaxUrl + "?method=GetTempletList";
            var colNames = ['TempID', '模板代码', '模板标题', '阿里模板代码', '模板描述', '是否删除', '创建日期'];
            var colModel = [
				{ name: 'TempID', index: 'TempID', width: 60, editable: false, hidden: true },
				{ name: 'TempAppCode', index: 'TempAppCode', width: 50, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} },
				{ name: 'Title', index: 'Title', width: 50, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc'] } },
				{ name: 'AliTempletCode', index: 'AliTempletCode', width: 50, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc'] } },
                { name: 'TempletDes', index: 'TempletDes', width: 80, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} },
                { name: 'IsDelete', index: 'IsDelete', search: false, width: 40, editable: false,
                    formatter: function (value) {
                        if (value.toString() == "True") {
                            return "是";
                        }
                        else {
                            return "否";
                        }
                    }
                },
				{ name: 'CreateDate', index: 'CreateDate', width: 60, editable: false, formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d' }, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'], dataInit: GridSelectDatePick} }
			];
            var dfop =
            {
                GridID: gridTableID,
                GridPagerID: gridPagerID,
                Url: url,
                ColNames: colNames,
                ColModel: colModel,
                Caption: "模板列表",
                SortName: "CreateDate",
                Height: 355,
                OndblClickRow: Look
            };
            showJqGrid(dfop);
            GetOperateAuth({ Url: "../../Handlers/Handler_UserAuth.ashx?method=GetAuthOperate", GridID: gridTableID, GridPagerID: gridPagerID, ModuleID: "<%=strRequestID %>" });
        });

        function CBClose() {
            $.colorbox.close();
        }

        function CBClose_Load() {
            $.colorbox.close();
            showDialogMessage("操作数据成功");
            Reload();
        }

        function Reload() {
            $("#" + gridTableID).trigger("reloadGrid");
        }
        
    </script>
</asp:Content>
